import React, { Component } from 'react'
import { connect } from 'react-redux'
import PropTypes from 'prop-types'
import { Switch, Redirect } from 'react-router'
import { PrivateRoute } from 'components/route'
import { project as projectDuck } from 'ducks'
import TaskList from './taskList'
import NewTask from './new'

class Members extends Component {
  static propTypes = {
    actionSetActiveTaskTab: PropTypes.func.isRequired,
  }

  componentDidMount = () => {
    const { actionSetActiveTaskTab } = this.props
    actionSetActiveTaskTab('review')
  }

  render() {
    const { match, location } = this.props
    return (
      <Switch location={location}>
        <PrivateRoute path={`${match.url}/`} component={TaskList} exact />
        <PrivateRoute path={`${match.url}/new`} component={NewTask} exact />
        <Redirect from={`${match.url}`} to={`${match.url}`} />
      </Switch>
    )
  }
}

const mapDispatchToProps = {
  actionSetActiveTaskTab: projectDuck.creators.actionSetActiveTaskTab,
}

export default connect(
  null,
  mapDispatchToProps,
)(Members)
